package cn.zhukelili.guava;

import com.google.common.base.Joiner;
import com.google.common.base.Stopwatch;
import com.google.common.collect.Maps;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @author hhbeast
 * @create 2018-12-12-13:30
 **/
public class TestDemo {

    /**
     * 将list转换为特定规则的字符串
     */
    @Test
    public void Lis2String(){
        List<String> list = new ArrayList<String>();
        list.add("aa");
        list.add("bb");
        list.add("cc");

        String result = Joiner.on("-").join(list);

        System.out.println(result);
    }

    /**
     * 将map转换为特定规则的字符串
     */
    @Test
    public void Map2String(){
        Stopwatch stopwatch = Stopwatch.createStarted();
        Map<String, Integer> map = Maps.newHashMap();
        map.put("xiaoming", 12);
        map.put("xiaohong",13);

        String result = Joiner.on(",").withKeyValueSeparator("=").join(map);

        System.out.println(result);
        long nanos = stopwatch.elapsed(TimeUnit.MILLISECONDS);
        System.out.println(nanos);
    }


}
